﻿using System.Diagnostics;
using System.IO;

namespace AvaloniaMVVMSample.Models;

public class FileModel : SystemModel
{
    public string Name { get; set; }
    public string Path { get; set; }
    public string Size { get; set; }
    public string Extension { get; set; }

    public FileModel(FileInfo file)
    {
        Name = file.Name;
        Path = file.FullName;
        Extension = file.Extension;

        Size = file.Length > long.MaxValue / 2 ? "" : file.Length.GetSize();
    }

    public FileModel(string path)
    {
        var file = new FileInfo(path);
        Path = path;
        Name = file.Name;
        Extension = file.Extension;
        Size = file.Length.GetSize();
    }

    public void Open()
    {
        Process.Start(new ProcessStartInfo() { FileName = Path, UseShellExecute = true });
    }
}